package com.searchengine;

import com.searchengine.config.ProcessMonitor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.ApplicationContext;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

/**
 * 搜索引擎应用主类
 */
@SpringBootApplication(scanBasePackages = "com.searchengine")
@EntityScan(basePackages = "com.searchengine.entity")
@EnableJpaRepositories(basePackages = "com.searchengine.repository")
public class Application {

    public static void main(String[] args) {
        // 设置默认配置文件为H2
        System.setProperty("spring.profiles.active", "h2");
        
        // 启动Spring应用
        ApplicationContext context = SpringApplication.run(Application.class, args);
        
        // 获取ProcessMonitor实例
        ProcessMonitor processMonitor = context.getBean(ProcessMonitor.class);
        
        // 监控系统资源
        processMonitor.monitorResources();
        
        // 输出系统负载信息
        String systemLoad = processMonitor.getSystemLoad();
        System.out.println("系统监控状态: " + systemLoad);
        
        System.out.println("搜索引擎后端服务已成功启动！");
    }
}